package org.epidroid.epidroid.news.engine;

import java.util.Iterator;
import java.util.List;

import org.apache.commons.net.nntp.NewsgroupInfo;

public class Group implements Comparable<Group> {
	private String _title;
	private long _count;
	private List<Topic> _topics = null;
	private Boolean _isFav = false;

	public Group(NewsgroupInfo info) {
		_title = info.getNewsgroup();
		_count = info.getArticleCountLong();
	}
	
	public Group(String title, long count) {
		_title = title;
		_count = count;
	}

	public Topic getTopicById(String id) {
		for (Iterator<Topic> it = _topics.iterator(); it.hasNext();) {
			Topic topic = (Topic) it.next();
			if (topic.getServId().equals(id)) {
				return topic;
			}
		}
		return null;
	}

	public void setTopics(List<Topic> topics) {
		_topics = topics;
		addRepliesToList();
	}

	public String getTitle() {
		return _title;
	}
	
	public long getCount() {
		return _count;
	}
	
	private void addRepliesToList() {
		for (Topic topic : _topics) {
			topic.addRepliesToList();
		}
	}

	public Boolean isFav() {
		return _isFav;
	}

	public void setFav(Boolean isFav) {
		this._isFav = isFav;
	}

	@Override
	public int compareTo(Group another) {
		return _title.compareTo(another._title);
	}
}
